#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 100100
using namespace std;
struct Tree{
	Tree *ls,*rs;
	int num;
	Tree(Tree*_,Tree*__,int ___):ls(_),rs(__),num(___){}
}*tree[M];
Tree* Build_Tree(Tree *p,int x,int y,int z)
{
	int mid=x+y>>1;
	if(x==y)
		return new Tree(tree[0],tree[0],p->num+1);
	if(z<=mid)
		return new Tree(Build_Tree(p->ls,x,mid,z),p->rs,p->num+1);
	else
		return new Tree(p->ls,Build_Tree(p->rs,mid+1,y,z),p->num+1);
}
int Get_Ans(Tree *p1,Tree *p2,Tree *p3,Tree *p4,int x,int y,int k)
{
	int mid=x+y>>1;
	if(x==y)
		return mid;
	int temp = p1->ls->num + p2->ls->num - p3->ls->num - p4->ls->num ;
	if(k<=temp) return Get_Ans( p1->ls , p2->ls , p3->ls , p4->ls , x , mid , k );
	else return Get_Ans( p1->rs , p2->rs , p3->rs , p4->rs , mid+1 , y , k-temp );
}
struct abcd{
	int to,next;
}table[M<<1];
int head[M],tot;
int n,m,ans;
int a[M],fa[M][20],dpt[M];
pair<int,int>b[M];
void Add(int x,int y)
{
	table[++tot].to=y;
	table[tot].next=head[x];
	head[x]=tot;
}
void DFS(int x)
{
	int i;
	dpt[x]=dpt[fa[x][0]]+1;
	tree[x]=Build_Tree(tree[fa[x][0]],1,n,a[x]);
	for(i=head[x];i;i=table[i].next)
	{
		if(table[i].to==fa[x][0])
			continue;
		fa[table[i].to][0]=x;
		DFS(table[i].to);
	}
}
int LCA(int x,int y)
{
	int j;
	if(dpt[x]<dpt[y])
		swap(x,y);
	for(j=19;~j;j--)
		if(dpt[fa[x][j]]>=dpt[y])
			x=fa[x][j];
	if(x==y)
		return x;
	for(j=19;~j;j--)
		if(fa[x][j]!=fa[y][j])
			x=fa[x][j],y=fa[y][j];
	return fa[x][0];
}
int Query(int x,int y,int k)
{
	int lca=LCA(x,y);
	return Get_Ans( tree[x] , tree[y] , tree[lca] , tree[fa[lca][0]] , 1 , n , k );
}
int main()
{
	
	//freopen("count.in","r",stdin);
	//freopen("count.out","w",stdout);
	
	int i,j,x,y,k;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i].first);
		b[i].second=i;
	}
	sort(b+1,b+n+1);
	for(i=1;i<=n;i++)
		a[b[i].second]=i;
	for(i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		Add(x,y);
		Add(y,x);
	}
	tree[0]=new Tree(0x0,0x0,0);
	tree[0]->ls=tree[0]->rs=tree[0];
	DFS(1);
	for(j=1;j<=19;j++)
		for(i=1;i<=n;i++)
			fa[i][j]=fa[ fa[i][j-1] ][j-1];
	for(i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&k);
		printf("%d",ans=b[Query(x^ans,y,k)].first);
		if(i!=m)
			puts("");
	}
}

